package com.dh.bm.dao.impl;

import com.dh.bm.common.JDBCUtil;
import com.dh.bm.dao.OrderDao;
import com.dh.bm.util.DateUtil;

import java.sql.PreparedStatement;
import java.sql.SQLException;

public class OrderDaoImpl implements OrderDao {
    @Override
    public boolean borrow_book(int book_id, int user_id) {
        String sql = "insert into book_order (book_id,borrow_time,user_id,created_time,updated_time) values(?,?,?,?,?)";
        PreparedStatement ps = JDBCUtil.getStatement(sql);
        try {
            ps.setInt(1, book_id);
            ps.setString(2,DateUtil.getNowDate());
            ps.setInt(3, user_id);
            ps.setString(4, DateUtil.getNowDate());
            ps.setString(5, DateUtil.getNowDate());

            return ps.executeUpdate() > 0;// 执行sql
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            JDBCUtil.close();
        }
        return false;

    }

    @Override
    public boolean return_book(int book_id, int user_id) {
        String sql = "update";
        return false;
    }
}
